<template>
  <starTable
    :ref="ref"
    :data="data"
    v-bind="attrs"
    @loadPage="loadPage"
    @handleEdit="handleEdit"
    @handleDelete="handleDelete"
    @handleDetail="handleDetail"
    @handleClick="handleClick"
    @handleDbClick="handleDbClick"
    @handleCreate="handleCreate"
    @handleDeleteMultiple="handleDeleteMultiple"
    @handleSearch="handleSearch"
    @handleReset="handleReset"
    @handleSelect="handleSelect"
  ></starTable>
</template>

<script>
const ref = "planBotTable";
export default {
  name: ref,
  inject: ["anc"],
  data() {
    return {
      ref,
    };
  },
  props: {
    data: {
      default: () => {
        return [];
      },
    },
  },
  watch: {},
  computed: {
    attrs() {
      return {
        config: {
          autoHeight: true,
          search: false,
          addButton: false,
          batchDeleteButton: false,
          downloadIcon: false,
          uploadIcon: false,
          uploadUrl: "/",
          tableSizeIcon: false,
          fullscreenIcon: false,
          refreshIcon: false,
          columnSettingIcon: false,
          action: false, // 操作
          checkColumnDisabled: true,
          additionalAction: false, // 新增自定义
          navigation: false,
        },
        loading: false, //是否显示加载中提示
        tableStyle: {}, //表格样式
        tableTitle: "已绑定订单", //表格标题
        pageSizeOpts: [10, 30, 50, 100],
        pageNavigation: {
          total: 0,
          pageSize: 10,
          pageNumber: 1,
        },
        queryFormItem: [],
        collapseFormItem: [],
        btnShowFun: (row, key) => {
          return true;
        },
        rowbgc: "",
        columns: [
          {
            key: "planBatchNo",
            title: "计划批次号",
            minWidth: 200,
            align: "center",
            show: true,
          },
          {
            key: "productId",
            title: "产物规格",
            minWidth: 200,
            align: "center",
            show: true,

            render: (h, params) => {
              return h(
                "div",
                {},
                this.getOptionValue(
                  this.anc.productOptions,
                  params.row.productId
                )
              );
            },
          },
          // {
          //   key: "planType",
          //   title: "计划类型",
          //   minWidth: 200,
          //   align: "center",
          //   show: true,
          //   config: { type: "text" },
          // },
          {
            key: "status",
            title: "状态",
            minWidth: 200,
            align: "center",
            show: true,
            // config: {
            //   type: "span",
            //   text: (row, column, index) => {
            //     return  row.status + "-" + index;
            //   },
            //   style: (row, column, index) => {
            //     if (index == 0) {
            //       return {
            //         color: "red",
            //       };
            //     }
            //   },
            // },
          },
          {
            key: "totalCapacity",
            title: "计划产量",
            minWidth: 200,
            align: "center",
            show: true,
          },
          {
            key: "usedCapacity",
            title: "已产量",
            minWidth: 200,
            align: "center",
            show: true,
          },
          {
            key: "restCapacity",
            title: "剩余未产",
            minWidth: 200,
            align: "center",
            show: true,
          },
          {
            key: "remark",
            title: "备注",
            minWidth: 200,
            align: "center",
            show: true,
          },
        ],
        additionalAction: {
          key: "additionalAction",
          title: "附加操作",
          slot: "additionalAction",
          width: 200,
          fixed: "right",
          align: "center",
          show: true,
          buttons: [
            {
              title: "下派",
              style: (row, column, index, item, i) => {
                console.log({ row, column, index, item, i });
                if (!(this.anc.mainStatus != "创建" && row.status == "启用")) {
                  return {
                    "pointer-events": "none",
                    color: "gray",
                  };
                }
              },
              event: (row, index) => this.anc.orderTableExecution(row, index),
            },
          ],
        },
      };
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);
      // this.loadPage(this.pageNavigation, {});
    });
  },
  methods: {
    loadPage(pageNavigation, filter) {
      // this.anc.rightLoadPage(pageNavigation, filter);
      // this.anc.rightNotBindTable(pageNavigation, filter)
    },
    handleEdit(row, index) {},
    handleDelete(row, index) {
      this.anc.orderTableDelete(row, index);
    },
    handleDetail(row, index) {},
    handleClick(row, index) {},
    handleSelect(selection) {
      this.anc.rightSelect(selection);
    },
    handleDbClick(row, index) {},
    handleCreate() {
      this.anc.orderTableCreate();
    },
    handleDeleteMultiple(selection) {},
    handleReset() {},
    handleSearch(filter) {},
    getOptionValue(options, value, key = "label") {
      let dataValue = "";
      let index = options.findIndex((d) => d.value === value);
      if (index !== -1) {
        dataValue = options[index][key];
      }
      return dataValue;
    },
  },
};
</script>
<style scoped></style>
